package us.codecraft.webmagic.model.samples;

import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.model.OOSpider;
import us.codecraft.webmagic.model.annotation.ExtractBy;

public class HotNews {
    @ExtractBy("/html[@class='expanded']/body/div[@id='body']/div[@id='col_toparea']/div[@class='l-right-col']/div[@class='mod']/div[@class='bd']/div[@id='instant-news']/ul[@class='ulist mix-ulist']/li[1]/a[@class='title']")
    private String title;

    @ExtractBy("/html[@class='expanded']/body/div[@id='body']/div[@id='col_toparea']/div[@class='l-right-col']/div[@class='mod']/div[@class='bd']/div[@id='instant-news']/ul[@class='ulist mix-ulist']/li[1]/a[@class='title']")
    private String cont;

    @Override
    public String toString() {
        return "cont{" +
                "title='" + title + '\'' +
                ", cont='" + cont + '\'' +
                '}';
    }
    public static void main(String[] args) {
        OOSpider ooSpider = OOSpider.create(Site.me().setSleepTime(0), HotNews.class);
        //single download
        HotNews baike = ooSpider.<HotNews>get("https://news.baidu.com/guoji");
        System.out.println(baike);
        String description = baike.getTitle();
        String a = baike.getCont();
        System.out.println(description);
        System.out.println(a);
        ooSpider.close();
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getCont() {
        return cont;
    }

    public void setCont(String cont) {
        this.cont = cont;
    }
}
